<extend name="Public/base"/>

<block name="body">
  <!-- 标题栏 -->
  <div class="main-title">
    <h2>[{$model['title']}] 列表</h2>
  </div>

  <!-- 数据列表 -->
  <form id="form1" name="form1" action="{:U('Admin/ProductOrder/data_export')}" method="post" class="form-horizontal">
    <div class="order_filter product_order_filter">
      <div class="grid">
        <div class="date">
          <input type="text" class="form-control begin_time" name="begin_time" placeholder="请选择开始日期" value="{$default_filter['begin_time']}">
        </div>
      </div>
      <div class="grid">
        <div class="date">
          <input type="text" class="form-control end_time" name="end_time" placeholder="请选择结束日期" value="{$default_filter['end_time']}">
        </div>
      </div>
      <div class="grid">
        <div class="date">
          <select class="form-control ticket-select" id="attribute_select" name="attribute_select">
            <option value="">全部商品</option>
            <volist name="attributes" id="attribute">
              <option value="{$attribute.id}">{$attribute.product_name}({$attribute.attribution_name})</option>
            </volist>
          </select>
        </div>
      </div>

      <div class="grid-whole">
        <span>状态选择：</span>
        <input type="hidden" id="status" name="status" value="">
        <input type="checkbox" id="0" value="0"> <label for="0">未支付</label>
        <input type="checkbox" id="1" value="1"> <label for="1">已支付</label>
        <input type="checkbox" id="2" value="2"> <label for="2">已发货</label>
        <input type="checkbox" id="3" value="3"> <label for="3">已完成</label>
        <input type="checkbox" id="4" value="4"> <label for="4">库存不足，交易关闭</label>
        <input type="checkbox" id="5" value="5"> <label for="5">其他原因，交易关闭</label>
        <input type="checkbox" id="6" value="6"> <label for="6">用户取消，交易关闭</label>
        <div class="cf grid buttons">
          <button class="btn btn-primary" type="button" onclick="clearFilter()">清空</button>
          <button class="btn btn-primary" type="button" onclick="filter()">筛选</button>
          <button class="btn btn-primary" type="submit" target-form="form-horizontal">导 出</button>
        </div>
      </div>
      
    </div>
  </form>

  <div class="filter-count">
    <ul>
      <li>
        <b>{$count}</b>
        <p>订单数</p>
      </li>
      <li>
        <b>{$filter_count['total_amount']}</b>
        <p>商品件数</p>
      </li>
      <li>
        <b>￥{$filter_count['total_price']}</b>
        <p>销售总额</p>
      </li>
    </ul>
  </div>

  <div class="cf">
    <div class="fl">
      <empty name="model.extend">
       <div class="tools">
        <!-- <a class="btn btn-primary" href="{:U('add?model='.$model['id'])}">新 增</a> -->
        <!-- <button class="btn ajax-post confirm btn-primary" target-form="ids" url="{:U('del?model='.$model['id'])}">删 除</button> -->
      </div>
    </empty>
  </div>
  <!-- 高级搜索 -->
  <!-- <div class="search-form cf">
   <div class="sleft">
    <input type="text" name="{$model['search_key']|default='title'}" class="search-input" value="{:I('title')}" placeholder="请输入关键字">
    <a class="sch-btn" href="javascript:;" id="search" url="{:U('Think/lists','model='.$model['name'],false)}"><i class="btn-search"></i></a>
  </div> 

</div>-->
</div>


<!-- 数据列表 -->
<div class="data-table">
  <div class="data-table table-striped">
    <table>
      <!-- 表头 -->
      <thead>
        <tr>
          <th class="row-selected row-selected">
            <input class="check-all" type="checkbox">
          </th>
          <volist name="list_grids" id="field">
            <th>{$field.title}</th>
          </volist>
        </tr>
      </thead>

      <!-- 列表 -->
      <tbody>
        <volist name="list_data" id="data">
          <tr>
            <td><input class="ids" type="checkbox" value="{$data['id']}" name="ids[]"></td>
            <volist name="list_grids" id="grid">
              <td>{:get_list_field($data,$grid)}</td>
            </volist>
          </tr>
        </volist>
      </tbody>
    </table>
  </div>
</div>
<div class="page">
  {$_page|default=''}
</div>
</block>

<block name="script">
  <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
  <php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
  <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
  <script type="text/javascript">
  $(function(){
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
    var query  = $('.search-form').find('input').serialize();
    query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
    query = query.replace(/^&/g,'');
    if( url.indexOf('?')>0 ){
      url += '&' + query;
    }else{
      url += '?' + query;
    }
    window.location.href = url;
  });

    //回车自动提交
    $('.search-form').find('input').keyup(function(event){
      if(event.keyCode===13){
        $("#search").click();
      }
    });

    $('.begin_time').datetimepicker({
      format: 'yyyy-mm-dd',
      language:"zh-CN",
      minView:2,
      autoclose:true
    });

    $('.end_time').datetimepicker({
      format: 'yyyy-mm-dd',
      language:"zh-CN",
      minView:2,
      autoclose:true
    });

    var default_status = GetQueryString("status")?GetQueryString("status"):null;

    if(default_status!=null){
      $('input[name=status]').val(default_status);
      default_status = default_status.split(',');
      var checkbox = $('input[type=checkbox]');
      for(var j=0;j<default_status.length;j++){
        for(var i=0;i<checkbox.length;i++){
          if(checkbox[i].value == default_status[j]){
            checkbox[i].checked = true;
          }
        }
      }
    }

    var default_attribution = "{$default_filter['attribute_select']}";
    $('#attribute_select').val(default_attribution);

  })

  $('input[type=checkbox]').change(function(){
    var checked_array = [];
    $('input[type=checkbox]:checked').each(function(i,o){
        checked_array.push(o.value);
    });
    $('#status').val(checked_array.join(','));
  });

  function filter(){
    var begin_time = $('.begin_time').val();
    var end_time = $('.end_time').val();
    var status = $('#status').val();
    var attribution = $('#attribute_select').val();
    window.location.href = 'index.php?s=Admin/ProductOrder/lists&model=product_order&begin_time='+begin_time+'&end_time='+end_time+'&status='+status+'&attribute_select='+attribution;
  }

  function GetQueryString(name)
  {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
  }

  function clearFilter(){
    window.location.href = 'index.php?s=Admin/ProductOrder/lists&model=product_order';
  }

  function sendProduct(product_order_id){
    if(confirm('您是否确认要发货？')){
      var name = "express_num_"+product_order_id;
      var co = "express_co_"+product_order_id;
      var express_no = $("input[name='"+name+"']").val();
      var express_co = $("input[name='"+co+"']").val();
      window.location.href = 'index.php?s=Admin/ProductOrder/sendProduct/id/'+product_order_id+'/express_num/'+express_no+'/express_co/'+express_co;
    }
    
  }
</script>
</block>
